﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Assignment1
{
    enum TileType
    {
        START, GOAL, SOLID, OPEN
    }

    class Tile
    {
        static Texture2D sTexture;

        private int x, y;
        private TileType tileType;
        private Tile north, east, south, west;
        private bool isPartOfPath = false;

        private bool isOpen = true;
        private int hScore;
        private int gScore = int.MaxValue;

        public static void LoadContent(GraphicsDevice graphicDevice)
        {
            sTexture = new Texture2D(graphicDevice, 1, 1);
            sTexture.SetData(new Color[] { Color.White });
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            int tileSize = 20;
            Color color;

            switch (tileType)
            {
                case Assignment1.TileType.START:
                    color = Color.Red;
                    break;
                case TileType.GOAL:
                    color = Color.Green;
                    break;
                case TileType.OPEN:
                    color = Color.Transparent;
                    break;
                case TileType.SOLID:
                    color = Color.BurlyWood;
                    break;
                default:
                    color = Color.LightBlue;
                    break;
            }

            spriteBatch.Draw(sTexture, new Rectangle((x * tileSize), (y * tileSize), tileSize, tileSize), color);
            spriteBatch.Draw(sTexture, new Rectangle((x * tileSize), (y * tileSize), tileSize, 1), Color.DarkGray);
            spriteBatch.Draw(sTexture, new Rectangle((x * tileSize), (y * tileSize) + tileSize, tileSize, 1), Color.DarkGray);
            spriteBatch.Draw(sTexture, new Rectangle((x * tileSize), (y * tileSize), 1, tileSize), Color.DarkGray);
            spriteBatch.Draw(sTexture, new Rectangle((x * tileSize) + tileSize, (y * tileSize), 1, tileSize), Color.DarkGray);
        }

        #region properties
        public Tile North
        {
            get { return north; }
            set { north = value; }
        }

        public Tile East
        {
            get { return east; }
            set { east = value; }
        }

        public Tile South
        {
            get { return south; }
            set { south = value; }
        }

        public Tile West
        {
            get { return west; }
            set { west = value; }
        }

        public TileType TileType
        {
            get { return tileType; }
            set { tileType = value; }
        }

        public int X
        {
            get { return x; }
            set { x = value; }
        }

        public int Y
        {
            get { return y; }
            set { y = value; }
        }

        bool IsPartOfPath
        {
            get { return isPartOfPath; }
            set { isPartOfPath = value; }
        }
        #endregion
    }
}
